# == Coding: UTF-8 ==
# @Project :        DormitoryManagementSystem
# @fileName         run_login.py  
# @version          v0.5
# @author           Echo
# @GiteeWarehouse   https://gitee.com/liu-long068/
# @editsession      2023/6/1
# @Software:        PyCharm
# ====/******/=====
import sys

from login import Login
from register import Register
from forget_password import ForgetPassword
from public.menus.menu import Menu


def normal_exit():
    print("退出成功！欢迎再次使用！")
    sys.exit()


def handle_invalid_choice():
    print("无效操作！请重新输入")


def main():
    menu = Menu()
    login = Login()
    register = Register()
    fp = ForgetPassword()
    options = {
        '1': login.login_business,
        '2': register.register_business,
        '3': {
            '1': fp.reset_password,
            '0': menu.home_menu
        },
        '0': normal_exit
    }
    while True:
        menu.home_menu()
        choice = input("请操作：")
        if choice in options:
            option = options[choice]
            if callable(option):
                option()
            else:
                while True:
                    option_menu = option
                    menu.home_submenu()
                    sub_choice = input("请操作：")
                    if sub_choice == '0':
                        break
                    elif sub_choice in option_menu:
                        sub_option = option_menu[sub_choice]
                        if callable(sub_option):
                            sub_option()
                        else:
                            handle_invalid_choice()
                    else:
                        handle_invalid_choice()
        else:
            handle_invalid_choice()


main()
